﻿using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Week6Music_API_and_Angular_.Data;
using Week6Music_API_and_Angular_.Data.Model;

namespace Week6Music_API_and_Angular_.Data
{
    public static class Seeders
    {
        private static string Test;
        private static string Admin;
        private static string David;
        private static string Quoc;
        private static string Gio;
        private static string Anna;
        private static string Jeremy;
        private static string Isaih;
        private static string Jacquie;

        public static void Seed(ApplicationDbContext db,
            bool roles = true,
            bool users = true,
            bool artists = true,
            bool events = true)
        {
            if (roles) seedroles(db);
            if (users) seedusers(db);

            Test = db.Users.FirstOrDefault(x => x.UserName == "test@test.com").Id;
            Admin = db.Users.FirstOrDefault(x => x.UserName == "admin@test.com").Id;
            David = db.Users.FirstOrDefault(x => x.UserName == "david@test.com").Id;
            Quoc = db.Users.FirstOrDefault(x => x.UserName == "quoc@test.com").Id;
            Gio = db.Users.FirstOrDefault(x => x.UserName == "gio@test.com").Id;
            Anna = db.Users.FirstOrDefault(x => x.UserName == "anna@test.com").Id;
            Jeremy = db.Users.FirstOrDefault(x => x.UserName == "jeremy@test.com").Id;
            Isaih = db.Users.FirstOrDefault(x => x.UserName == "isaih@test.com").Id;
            Jacquie = db.Users.FirstOrDefault(x => x.UserName == "jacquie@test.com").Id;

            if (artists) seedArtist(db);
            if (events) seedevents(db);
        }

        private static void seedroles(ApplicationDbContext db)
        {
            var store = new RoleStore<IdentityRole>(db);
            var manager = new RoleManager<IdentityRole>(store);
            if (!manager.RoleExists(Roles.USER))
            {
                manager.Create(new IdentityRole() { Name = Roles.USER });
            }
            if (!manager.RoleExists(Roles.ADMIN))
            {
                manager.Create(new IdentityRole() { Name = Roles.ADMIN });
            }
        }

        private static void seedusers(ApplicationDbContext db)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if (!db.Users.Any(x => x.UserName == "test@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "test@test.com",
                    UserName = "test@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "admin@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "admin@test.com",
                    UserName = "admin@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.ADMIN);
            }
            if (!db.Users.Any(x => x.UserName == "david@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "david@test.com",
                    UserName = "david@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "quoc@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "quoc@test.com",
                    UserName = "quoc@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "gio@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "gio@test.com",
                    UserName = "gio@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "anna@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "anna@test.com",
                    UserName = "anna@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "jeremy@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "jeremy@test.com",
                    UserName = "jeremy@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "isaih@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "isaih@test.com",
                    UserName = "isaih@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "jacquie@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "jacquie@test.com",
                    UserName = "jacquie@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
        }

        private static void seedevents(ApplicationDbContext db)
        {
            db.Events.AddOrUpdate(
                e => e.Id,
                new Event { EventName = "Taylor-Palooza", Id = 1, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 1, OpeningArtistID = 2, price = 100.99, ZipCode = 99501, EventPoster = "http://th04.deviantart.net/fs70/PRE/i/2012/026/c/e/naf_concert_poster_by_jasonserres-d4nok7u.jpg" },
                new Event { EventName = "A Bigger Bang Tour", Id = 2, Date = Convert.ToDateTime("7/04/2015"), FeaturedArtistID = 16, OpeningArtistID = 4, price = 20.00, ZipCode = 94601, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_05.jpg" },
                new Event { EventName = "The Wall Live", Id = 3, Date = Convert.ToDateTime("8/26/2015"), FeaturedArtistID = 15, OpeningArtistID = 3, price = 25.00, ZipCode = 94601, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_06.jpg" },
                new Event { EventName = "Black Ice World Tour", Id = 4, Date = Convert.ToDateTime("5/29/2015"), FeaturedArtistID = 12, OpeningArtistID = 16, price = 1.00, ZipCode = 94601, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_071.png" },
                new Event { EventName = "Black Ice World Tour", Id = 4, Date = Convert.ToDateTime("5/29/2015"), FeaturedArtistID = 14, OpeningArtistID = 13, price = 1.00, ZipCode = 94601, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_08.jpg" },
                new Event { EventName = "Vertigo Tour", Id = 5, Date = Convert.ToDateTime("9/29/2015"), FeaturedArtistID = 11, OpeningArtistID = 12, price = 60.00, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_09.jpg" },
                new Event { EventName = "The Police Reunion Tour", Id = 6, Date = Convert.ToDateTime("10/29/2015"), FeaturedArtistID = 4, OpeningArtistID = 11, price = 75.75, ZipCode = 99501, EventPoster = "http://www.absurdintellectual.com/wp-content/uploads/2011/02/il_fullxfull.221401903.jpg" },
                new Event { EventName = "Wrecking Ball World Tour", Id = 7, Date = Convert.ToDateTime("8/05/2015"), FeaturedArtistID = 5, OpeningArtistID = 10, price = 86.23, ZipCode = 94602, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_10.jpg" },
                new Event { EventName = "Licks Tour", Id = 16, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 6, OpeningArtistID = 9, price = 10.22, ZipCode = 94602, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_12.jpg" },
                new Event { EventName = "The MDNA Tour", Id = 8, Date = Convert.ToDateTime("7/12/2015"), FeaturedArtistID = 7, OpeningArtistID = 14, price = 99.99, ZipCode = 94602, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_131.jpg" },
                new Event { EventName = "The Division Bell Your", Id = 9, Date = Convert.ToDateTime("7/13/2015"), FeaturedArtistID = 8, OpeningArtistID = 7, price = 120.23, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_14.jpg" },
                new Event { EventName = "The Magical Mystery Your", Id = 10, Date = Convert.ToDateTime("7/29/2015"), FeaturedArtistID = 9, OpeningArtistID = 6, price = 117.12, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_15.jpg" },
                new Event { EventName = "A Momentary Lapse pf Reason Tour", Id = 11, Date = Convert.ToDateTime("8/04/2015"), FeaturedArtistID = 10, OpeningArtistID = 5, price = 150.50, ZipCode = 94602, EventPoster = "http://cdn.rsvlts.com/wp-content/uploads/2012/05/The-Black-Keys-concert-posters-71.jpg" },
                new Event { EventName = "Bad", Id = 12, Date = Convert.ToDateTime("9/16/2015"), FeaturedArtistID = 1, OpeningArtistID = 11, price = 64.23, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_16.jpg" },
                new Event { EventName = "Steel Wheels Tour", Id = 13, Date = Convert.ToDateTime("7/11/2015"), FeaturedArtistID = 12, OpeningArtistID = 4, price = 75.46, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_17.jpg" },
                new Event { EventName = "Born in the U.S.A. Tour", Id = 14, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 1, OpeningArtistID = 14, price = 43.32, ZipCode = 99501, EventPoster = "http://www.umbrellastudio.com/wp-content/uploads/2013/10/20130323.png" },
                new Event { EventName = "Hell Freezes Over Tour", Id = 15, Date = Convert.ToDateTime("10/22/2015"), FeaturedArtistID = 12, OpeningArtistID = 2, price = 1000.00, ZipCode = 33619, EventPoster = "http://recordmecca.com/wp-content/uploads/2012/09/L1350897.jpg" },
                new Event { EventName = "Rhythm Nation 1814", Id = 17, Date = Convert.ToDateTime("5/20/2015"), FeaturedArtistID = 3, OpeningArtistID = 1, price = 12.23, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_182.png" },
                new Event { EventName = "Blond Ambition World Tour", Id = 18, Date = Convert.ToDateTime("6/06/2015"), FeaturedArtistID = 2, OpeningArtistID = 12, price = 50.20, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_19.jpg" },
                new Event { EventName = "The Rising Tour", Id = 19, Date = Convert.ToDateTime("7/18/2015"), FeaturedArtistID = 4, OpeningArtistID = 11, price = 26.23, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_03.jpg" },
                new Event { EventName = "Lost Highway Tour", Id = 20, Date = Convert.ToDateTime("7/19/2015"), FeaturedArtistID = 5, OpeningArtistID = 10, price = 24.25, ZipCode = 94617, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_04.jpg" },
                new Event { EventName = "The Circus Starring Britney Spears", Id = 21, Date = Convert.ToDateTime("7/14/2015"), FeaturedArtistID = 6, OpeningArtistID = 9, price = 27.46, ZipCode = 94610, EventPoster = "http://concertposter.org/-concertposters-aug09/coldplay-ohio.jpg" },
                new Event { EventName = "Turn it On Again The Tour", Id = 22, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 15, OpeningArtistID = 8, price = 50.60, ZipCode = 94610, EventPoster = "http://cdn.rsvlts.com/wp-content/uploads/2012/08/Mumford-Sons-Concert-Posters-26.jpg" },
                new Event { EventName = "Have a Nice Day Tour", Id = 23, Date = Convert.ToDateTime("8/16/2015"), FeaturedArtistID = 16, OpeningArtistID = 7, price = 89.87, ZipCode = 94610, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_20.jpg" },
                new Event { EventName = "The Circle Tour", Id = 24, Date = Convert.ToDateTime("8/22/2015"), FeaturedArtistID = 9, OpeningArtistID = 6, price = 465.23, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_01.jpg" },
                new Event { EventName = "The Truth About Love Tour", Id = 25, Date = Convert.ToDateTime("7/13/2015"), FeaturedArtistID = 10, OpeningArtistID = 5, price = 10.23, ZipCode = 94610, EventPoster = "http://recordmecca.com/wp-content/uploads/2012/11/L1350922.jpg" },
                new Event { EventName = "The Prismatic World Tour", Id = 26, Date = Convert.ToDateTime("7/10/2015"), FeaturedArtistID = 11, OpeningArtistID = 4, price = 50.75, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_21.jpg" },
                new Event { EventName = "Funhouse Tour", Id = 27, Date = Convert.ToDateTime("8/20/2015"), FeaturedArtistID = 12, OpeningArtistID = 3, price = 46.99, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_02.jpg" },
                new Event { EventName = "The Moonshine Jungle Tour", Id = 28, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 1, OpeningArtistID = 2, price = 88.54, ZipCode = 99501, EventPoster = "http://blogs.umsl.edu/news/files/2011/01/The_Shins.jpg" },
                new Event { EventName = "The World Magnetic Tour", Id = 29, Date = Convert.ToDateTime("9/30/2015"), FeaturedArtistID = 2, OpeningArtistID = 15, price = 60.23, ZipCode = 94610, EventPoster = "http://www.postercentral.com/Concert%20Posters/Before%20They%20Were%20Famous/BTWF%202/jackson_five_concert_poster.png" },
                new Event { EventName = "Belieeve Tour", Id = 30, Date = Convert.ToDateTime("9/01/2015"), FeaturedArtistID = 16, OpeningArtistID = 2, price = 75.65, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_22.jpg" },
                new Event { EventName = "Born This Way Ball", Id = 31, Date = Convert.ToDateTime("10/02/2015"), FeaturedArtistID = 16, OpeningArtistID = 3, price = 45.54, ZipCode = 94610, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_23.jpg" },
                new Event { EventName = "Progress Live", Id = 32, Date = Convert.ToDateTime("12/03/2015"), FeaturedArtistID = 5, OpeningArtistID = 4, price = 77.77, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_24.jpg" },
                new Event { EventName = "The Monster Ball Tour", Id = 33, Date = Convert.ToDateTime("5/05/2015"), FeaturedArtistID = 6, OpeningArtistID = 5, price = 66.60, ZipCode = 94610, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_25.jpg" },
                new Event { EventName = "Carter Show World Tour", Id = 34, Date = Convert.ToDateTime("6/15/2015"), FeaturedArtistID = 7, OpeningArtistID = 6, price = 3.33, ZipCode = 94610, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_26.jpg" },
                new Event { EventName = "Where We Are Tour", Id = 35, Date = Convert.ToDateTime("6/29/2015"), FeaturedArtistID = 8, OpeningArtistID = 13, price = 22.22, ZipCode = 99501, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_27.jpg" },
                new Event { EventName = "Wrecking Ball World Tour", Id = 36, Date = Convert.ToDateTime("8/06/2015"), FeaturedArtistID = 9, OpeningArtistID = 8, price = 12.20, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_29.jpg" },
                new Event { EventName = "Because We Can", Id = 37, Date = Convert.ToDateTime("9/07/2015"), FeaturedArtistID = 13, OpeningArtistID = 9, price = 10.21, ZipCode = 33619, EventPoster = "http://www.awwwards.com/awards/images/2011/07/gig_posters_30.jpg" },
                new Event { EventName = "Dance Dance Dance", Id = 38, Date = Convert.ToDateTime("7/13/2015"), FeaturedArtistID = 11, OpeningArtistID = 10, price = 12.12, ZipCode = 33619, EventPoster = "http://recordmecca.com/wp-content/uploads/2013/03/IMG_0343.jpg" },
                new Event { EventName = "Broadway Dreams", Id = 39, Date = Convert.ToDateTime("6/15/2015"), FeaturedArtistID = 12, OpeningArtistID = 11, price = 30.20, ZipCode = 33619, EventPoster = "http://nashvillegab.typepad.com/.a/6a00e552403d2f883301901ed56ddb970b-320wi" },
                new Event { EventName = "School House Rock", Id = 40, Date = Convert.ToDateTime("10/17/2015"), FeaturedArtistID = 1, OpeningArtistID = 12, price = 12.21, ZipCode = 33619, EventPoster = "http://www.blackballcorp.com/images/products/detail/1575.jpg" }
                );
        }

        private static void seedArtist(ApplicationDbContext db)
        {
            db.Artist.AddOrUpdate(
                x => x.Id,
            new Artist { Id = 1, Genre = "Country, Pop rock, Pop music", Name = "Taylor Swift", ImgUrl = "http://primetime.unrealitytv.co.uk/wp-content/uploads/2014/11/Screen-Shot-2014-11-19-at-19.46.27.png", OnTour = true },
            new Artist { Id = 2, Genre = "Rock", OnTour = true, ImgUrl = "http://www.billboard.com/files/styles/promo_650/public/media/john-mayer-650-430.jpg", Name = "John Mayer" },
            new Artist { Id = 3, Name = "Zach Brown Band", ImgUrl = "https://pbs.twimg.com/profile_images/573515607561269248/hz1fyYhJ.jpeg", OnTour = true, Genre = "Country, Southern Rock" },
            new Artist { Id = 4, Name = "50 Cent", Genre = "Hip Hop, Rap", OnTour = false, ImgUrl = "http://www.flow935.com/pics/Feeds/Articles/201565/922206/50.jpg" },
            new Artist { Id = 5, Name = "Maron 5", Genre = "Pop, Rock, Soul, Funk, Soft Rock", OnTour = true, ImgUrl = "http://www.billboard.com/files/styles/promo_650/public/media/maroon-5-upclose-terryrichardson650.jpg" },
            new Artist { Id = 6, Name = "Ed Seeran", Genre = "Pop, Contemporary, Folk, Hip hop, Acoustic", OnTour = false, ImgUrl = "http://www.kiss1023.ca/files/sheeran1.jpg" },
            new Artist { Id = 7, Name = "Big Sean", Genre = "Hip Hop, Rap", OnTour = true, ImgUrl = "http://oswego.edu/arts/wp-content/uploads/2015/05/Big-Sean-Chain.jpg" },
            new Artist { Id = 8, Name = "The Weekend", Genre = "PBR&B", OnTour = true, ImgUrl = "http://static.guim.co.uk/sys-images/Guardian/About/General/2012/11/8/1352400325976/Abel-Tesfaye-AKA-the-Week-011.jpg" },
            new Artist { Id = 9, Name = "Calvin Harris", Genre = "Electro house, Electopop, Nu-disco", OnTour = false, ImgUrl = "http://i1.dailyrecord.co.uk/incoming/article3802327.ece/ALTERNATES/s615/JS37593735.jpg" },
            new Artist { Id = 10, Name = "Florida Georgia Line", Genre = "Country", OnTour = true, ImgUrl = "http://static.underthegunreview.net/uploads/2014/08/Florida-Georgia-Line-Anything-Goes-2014.jpeg" },
            new Artist { Id = 11, Name = "Jason Derulo", Genre = "Contemporary R&B, pop, Hip hop", OnTour = false, ImgUrl = "http://www.officialcharts.com/media/647343/jason-derulo-everything-is-4-artwork.jpg?width=500&height=500" },
            new Artist { Id = 12, Name = "Eric Chruch", Genre = "Country, Rock and Roll", OnTour = true, ImgUrl = "http://cdn.stagebloc.com/production/photos/2912/original/20131216_191748_2912_647351.jpeg" },
            new Artist { Id = 13, Name = "Rihanna", Genre = "Regge, Pop, Hip hop", OnTour = true, ImgUrl = "http://www.nogenremusic.com/wp-content/uploads/2011/11/rihanna.jpg" },
            new Artist { Id = 14, Name = "David Guetta", Genre = "House, Electo", OnTour = false, ImgUrl = "http://www.audiocastle.me/uploads/albums/David_Guetta_%E2%80%93_Listen_Album_Download.jpg" },
            new Artist { Id = 15, Name = "Katy Perry", Genre = "Pop", OnTour = false, ImgUrl = "http://img11.hostingpics.net/pics/4184681381944361front.jpg" },
            new Artist { Id = 16, Name = "Eminem", Genre = "Rap", OnTour = true, ImgUrl = "http://assets-s3.usmagazine.com/uploads/assets/articles/74828-eminems-daughter-hailie-graduates-from-high-school-details/1403900539_187596325_eminem-zoom.jpg" },
            new Artist { Id = 17, Name = "Skrillex", Genre = "Edm", OnTour = true, ImgUrl = "http://addictedtoradio.com/wp-content/uploads/2015/02/skrillix.png" },
            new Artist { Id = 18, Name = "Outkast", Genre = "Rap", OnTour = false, ImgUrl = "http://static.guim.co.uk/sys-images/Music/Pix/pictures/2012/2/27/1330339837566/Outkast-Big-Boi-and-Andre-007.jpg" },
            new Artist { Id = 19, Name = "Kenny Chesney", Genre = "Country", OnTour = true, ImgUrl = "http://www.billboard.com/files/styles/promo_650/public/stylus/2236659-KennyChesney617-2012.jpg" },
            new Artist { Id = 20, Name = "Billy Currington", Genre = "Country", OnTour = true, ImgUrl = "http://www.israbox.com/uploads/posts/2011-01/1294517021_folder.jpg" },
            new Artist { Id = 21, Name = "AVicii", Genre = "House", OnTour = true, ImgUrl = "http://www.jamspreader.com/wp-content/uploads/2013/06/AviciiWakeMeUp-e1371373433616.jpg" }

        );
        }
    }
}